package plateforme.controlleur;

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.mysql.jdbc.ResultSet;
import com.mysql.jdbc.Statement;

/**
 * Servlet implementation class ControlleurGetAllProjet
 */
public class ControlleurGetAllProjet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	String page="modifier_projet.jsp";
	private ServletConfig config;
	
	public void init(ServletConfig config) throws ServletException{

		 this.config=config;

		 }
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//Establish connection to MySQL database
		String connectionURL = "jdbc:mysql://localhost:3306/laas";
		Connection connection= null;
		 ResultSet rs;
		 response.setContentType("text/html");
		 List<String> dataList = new ArrayList<String>();
		
		   try {

			 // Load the database driver

			  Class.forName("com.mysql.jdbc.Driver");

			  // Get a Connection to the database

			  connection = (Connection) DriverManager.getConnection(connectionURL, "root", ""); 
			//Select the data from the database
			 // String sql = "select * from fournisseur" ;
			  
		
			String sql1 = "select * from project" ;
			  Statement s = (Statement) connection.createStatement();

			  s.executeQuery (sql1);

			  rs = (ResultSet) s.getResultSet();

			  while (rs.next ()){
				  
			  
			   
			  //Add records into data list

			  dataList.add(rs.getString(1));

			  dataList.add(rs.getString(2));

			  dataList.add(rs.getString(3));
			  
			  dataList.add(rs.getString(4));
			  dataList.add(rs.getString(5));
			 System.out.println(rs.getString(1)+rs.getString(2)+rs.getString(3)+rs.getString(4)+rs.getString(5));
			  }

			  rs.close ();

			  s.close ();

			  }catch(Exception e){

			  System.out.println("Exception is ;"+e);

			  }
		 
			  

			  //Disptching request
	          
	        	  
		 request.setAttribute("data1",dataList);

		  //Disptching request
		  RequestDispatcher dispatcher = request.getRequestDispatcher(page);

		  if (dispatcher != null){

		  dispatcher.forward(request, response);

		  } 

		  }
		
			 
			
	}

			  
	   
		   
		 













	